<template>
  <div class="home">
    <el-container style="height: 100vh; border: 1px solid #eee">
      <el-aside
        :width="isCollapse ? '64px' : '200px'"
        style="background-color: rgb(238, 241, 246)"
      >
        <el-menu
          default-active="1-4-1"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          :collapse="isCollapse"
          router
        >
          <div class="login-moer">
            <span>Moer菜鸡互啄</span>
          </div>
          <el-submenu index="1">
            <template #title>
              <i class="el-icon-user-solid"></i>
              <span>权限管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/Worla" @click="addTab(editableTabsValue)"
                ><i class="el-icon-user"></i>用户管理</el-menu-item
              >
              <el-menu-item index="/Worls" @click="addTab(editableTabsValue)"
                ><i class="el-icon-user"></i>菜单管理</el-menu-item
              >
              <el-menu-item index="/World" @click="addTab(editableTabsValue)"
                ><i class="el-icon-user"></i>部门管理</el-menu-item
              >
              <el-menu-item index="/Worlf" @click="addTab(editableTabsValue)"
                ><i class="el-icon-user"></i>租户管理</el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>
          <el-submenu index="2">
            <template #title>
              <i class="el-icon-setting"></i>
              <span>系统管理</span>
            </template>
            <el-menu-item-group>
              <el-menu-item index="/Worlg" @click="addTab(editableTabsValue)"
                ><i class="el-icon-user"></i>日志管理</el-menu-item
              >
              <el-menu-item index="/Worlh" @click="addTab(editableTabsValue)"
                ><i class="el-icon-user"></i>文件管理</el-menu-item
              >
              <el-menu-item index="/Worlj" @click="addTab(editableTabsValue)"
                ><i class="el-icon-user"></i>字典管理</el-menu-item
              >
              <el-menu-item index="/Worlk" @click="addTab(editableTabsValue)"
                ><i class="el-icon-user"></i>参数管理</el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header>
          <div class="divrleft" @click="haeoipset">
            <i :class="isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'"></i>
          </div>
          <div class="divright">
            <el-dropdown>
              <i class="el-icon-setting" style="margin-right: 15px"></i>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>查看</el-dropdown-item>
                  <el-dropdown-item>新增</el-dropdown-item>
                  <el-dropdown-item>删除</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
            <span>王小虎</span>
          </div>
        </el-header>
        <el-main style="ackground-color: #fff">
          <el-tabs
            v-model="editableTabsValue"
            type="card"
            closable
            @tab-remove="removeTab"
          >
            <el-tab-pane
              v-for="item in editableTabs"
              :key="item.name"
              :label="item.title"
              :name="item.name"
            >
              {{ item.content }}
            </el-tab-pane>
          </el-tabs>
          <router-view> </router-view>
          <!-- <el-table :data="tableData">
            <el-table-column prop="date" label="日期" width="140">
            </el-table-column>
            <el-table-column prop="name" label="姓名" width="120">
            </el-table-column>
            <el-table-column prop="address" label="地址"> </el-table-column>
          </el-table> -->
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Home",
  components: {},
  data() {
    return {
      // 是否折叠菜单
      isCollapse: false,
      //二级导航参数
      editableTabsValue: "2",
      editableTabs: [
        {
          title: "首页",
          name: "1",
          content: "",
        },
      ],
      tabIndex: 2,
    };
  },
  methods: {
    // 点击折叠菜单
    haeoipset() {
      this.isCollapse = !this.isCollapse;
    },
    // 二级导航
    addTab(targetName) {

      let newTabName = ++this.tabIndex + "";
      this.editableTabs.push({
        title: "New Tab",
        name: newTabName,
        content: "",
      });
      this.editableTabsValue = newTabName;
      console.log(targetName);
    },
    removeTab(targetName) {
      let tabs = this.editableTabs;
      let activeName = this.editableTabsValue;
      if (activeName === targetName) {
        tabs.forEach((tab, index) => {
          if (tab.name === targetName) {
            let nextTab = tabs[index + 1] || tabs[index - 1];
            if (nextTab) {
              activeName = nextTab.name;
              console.log(activeName);
            }
          }
        });
      }

      this.editableTabsValue = activeName;
      this.editableTabs = tabs.filter((tab) => tab.name !== targetName);
    },
  },
};
</script>
<style lang="less" scoped>
.home {
  background-color: #dcdfe6;
}
.el-header {
  background-color: #409eff;
  color: #fff;
  line-height: 60px;

  .divrleft {
    display: inline-block;
    font-size: 25px;
  }
  .divright {
    float: right;
    font-size: 18px;
    display: inline-block;
    i {
      font-size: 18px;
    }
  }
}

.el-aside {
  -webkit-box-shadow: 2px 0 6px rgb(0 21 41 / 15%);
  box-shadow: 2px 0 6px rgb(0 21 41 / 15%);
  background-color: #fff;
  color: #fff;
}
.el-menu {
  height: 100%;
  box-shadow: 2px 0 6px rgb(0 21 41 / 15%);
  background-color: #fff;
  .login-moer {
    background-color: #409eff;
    color: #fff;
    height: 60px;
    padding: 0 20px;
    text-align: center;
    line-height: 60px;
    overflow: hidden;
  }
  .el-menu-item.is-active {
    background-color: #409eff;
    color: #fff;
  }
}
.el-menu-item-group__title {
  padding: 0;
}
</style>

